package com.hamster.crm.web;

import com.hamster.crm.pojo.Leverage;
import com.hamster.crm.pojo.LeverageConfig;
import com.hamster.crm.service.LeverageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 杠杆计划的Controller
 * @author Tarry
 * @create 2019/12/19 10:51
 */
@RestController
@RequestMapping("leverage")
public class LeverageController {
    @Autowired
    private LeverageService leverageService;

    /**
     * 插入一条新的杠杆计划
     * @param leverage
     * @return 返回状态码200
     */
    @PostMapping("insert")
    public ResponseEntity<Void> insertLeverage(@RequestBody Leverage leverage){
        leverageService.insertLeverage(leverage);
        return ResponseEntity.ok().build();
    }

    /**
     * 根据id删除指定的杠杆计划
     * @param ids
     * @return 状态码200
     */
    @PostMapping("delete")
    public ResponseEntity<Void> deleteLeverage(@RequestBody List<String> ids){
        leverageService.deleteLeverage(ids);
        return ResponseEntity.ok().build();
    }

    /**
     * 根据id查询杠杆计划内容
     * @param id
     * @return 杠杆计划内容
     */
    @GetMapping("get")
    public ResponseEntity<Leverage> getLeverageById(@RequestParam String id){
        Leverage leverage=leverageService.getLeverageById(id);
        return ResponseEntity.ok(leverage);
    }


    /**
     * 修改杠杆计划
     * @param leverage
     * @return 状态码200
     */
    @PostMapping("update")
    public ResponseEntity<Void> updateLeverage(@RequestBody Leverage leverage){
        leverageService.updateLeverage(leverage);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询所有杠杆计划
     * @return Leverage的list列表 状态码 200
     */
    @GetMapping("list")
    public ResponseEntity<List<Leverage>> listLeverages(){
        List<Leverage> leverageList = leverageService.listLeverages();
        return ResponseEntity.ok(leverageList);
    }

    /**
     * 设置杠杆参与人分成提成比例
     * @param leverageConfig
     * @return 状态码 200
     */
    @PostMapping("updateConfig")
    public ResponseEntity<Void> updateLeverageConfig(@RequestBody LeverageConfig leverageConfig){
        leverageService.updateLeverageConfig(leverageConfig);
        return ResponseEntity.ok().build();
    }

    /**
     * 获取杠杆参与人提成数据
     * @return LeverageConfig提成比例数据，状态码200
     */
    @GetMapping("getConfig")
    public ResponseEntity<LeverageConfig> getLeverageConfig(){
        LeverageConfig leverageConfig = leverageService.getLeverageConfig();
        return ResponseEntity.ok(leverageConfig);
    }

}
